FROM rust:1.56.1 as builder

RUN rustup component add rustfmt

ENV APP grpcservice
ENV BIN service

WORKDIR /usr/src/
# RUN USER=root cargo new $APP
RUN mkdir $APP
WORKDIR /usr/src/$APP
RUN mkdir -p .cargo
COPY config .cargo/
COPY . .

RUN cargo build --release --bin $BIN
# RUN strip /target/release/$BIN

FROM debian:buster-slim
RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/*
COPY --from=builder /target/release/$BIN /usr/local/bin/$BIN
CMD ["./$BIN"]